<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <div id="box">
      <!-- <ul>
            <li v-for="(v, index) in lest" :key="index">
               
                {{v.sex ===0?'男':'女'}}
            </li>
        </ul> -->
      <!-- 过滤器的使用方式 -->
      <ul>
        <li v-for="(v, index) in lest" :key="index">
          <!-- {{过滤的内容 | 过滤的方法}} -->
          {{v.sex| filterSex}}
        </li>
        <li v-for="(v, index) in lestArr">
          <!-- {{过滤的内容 | 过滤的方法}} -->
          {{v.sex| filterSex}}
        </li>
      </ul>
    </div>
    <div id="box1">{{0|fil}}</div>
    <script>
      //vue2有 vue3(methods)
      Vue.filter("fil", (val) => {
        return 111;
      });
      new Vue({
        el: "#box",
        data: {
          lest: [
            {
              sex: 0,
            },
            {
              sex: 1,
            },
          ],
          lestArr: [
            {
              sex: 1,
            },
            {
              sex: 1,
            },
          ],
        },
        //过滤器（局部过滤）
        filters: {
          filterSex(val) {
            //val 读取的是|前面的内容
            console.log(val);
            return val === 0 ? "男" : "女";
          },
        },
      });
      new Vue({
        el: "#box1",
      });
    </script>
  </body>
</html>
